<%@ page pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css"/>
    <title>商品添加</title>
    <style type="text/css">
        th{
            text-align: center;
        }

    </style>
    <script src="${pageContext.request.contextPath}/js/jquery-1.8.3.js"></script>
    <script>
        $(function () {
            $.ajax({
                url:"${pageContext.request.contextPath}/category/selectAllCategory",
                dataType:"json",
                success:function (result) {
                    //获取当前对象的类别id
                    var cid = "${p.category.id}";
                    var html="";
                    $(result).each(function (i,obj){
                        if(cid==obj.id){
                            html +='<option selected value="'+obj.id+'">'+obj.name+'</option>'
                        }else{
                            html +='<option value="'+obj.id+'">'+obj.name+'</option>'
                        }
                    })
                    $("select").html(html);
                }
            });
        })
    </script>
</head>
<body>
<div class="container">
    <div class="row">
        <nav class="navbar navbar-default">
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>

                    <a class="navbar-brand" href="#" style="font-size: 28px;">商品管理</a>
                </div>
                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li><a href="${pageContext.request.contextPath}/category/selectCategoryByPage">类别管理</a></li>
                        <li><a href="${pageContext.request.contextPath}/product/selectProducts">商品管理</a></li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="${pageContext.request.contextPath}/exit">退出系统 <span class="czs-out-l"></span></a></li>
                    </ul>
                </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
        </nav>
    </div>
    <div class="row">
        <div class="col-md-3">
        </div>
        <div class="col-md-6">
        </div>
        <div class="col-md-3">
            <p class="bg-warning" style="">
                欢迎:[再见孙悟空] &nbsp;&nbsp;&nbsp; <img src="${pageContext.request.contextPath}/img/girl.jpg" width="50px" class="img-rounded" alt="" />
            </p>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12" style="height: 10px;"></div>
    </div>
    <div class="row">
        <div class="col-md-2"></div>
        <div class="col-md-8" style="text-align: center;">
            <!--enctype="multipart/form-data" form表单加上此属性才能实现文件上传-->
            <form enctype="multipart/form-data" class="form-inline" action="${pageContext.request.contextPath}/product/updateProduct" method="post">
                <table class="table  table-bordered" style="width:100%;">
                    <tr class="bg-primary">
                        <td style="text-align: center;" colspan="2"><span style="font-size: 20px;">商品添加</span></td>
                    </tr>
                    <tr class="active">
                        <td style="width: 120px; vertical-align: middle">商品名<input type="hidden" name="p.pid" value="${p.pid}"></td>
                        <td><input type="text" style="width: 100%;" placeholder="请输入商品名" class="form-control" name="p.pname" value="${p.pname}"></td>
                    </tr>
                    <tr class="active">
                        <td style="width: 120px; vertical-align: middle">价格</td>
                        <td><input type="number" style="width: 100%;" placeholder="请输入价格" class="form-control" name="p.price" value="${p.price}"></td>
                    </tr>
                    <tr class="active">
                        <td style="width: 120px; vertical-align: middle">库存</td>
                        <td><input type="number" style="width: 100%;" placeholder="请输入库存" class="form-control" name="p.count" value="${p.count}"></td>
                    </tr>
                    <tr class="active">
                        <td style="width: 120px; vertical-align: middle">是否上架</td>
                        <td>
                             <input type="radio" name="p.status" value="0" checked>是
                             <input type="radio" name="p.status" value="1" >否
                        </td>
                    </tr>
                    <tr class="active">
                        <td style="width: 120px; vertical-align: middle">所属类别</td>
                        <td>
                            <select style="width: 50%;" class="form-control" name="p.category.id">
                            </select>
                        </td>
                    </tr>
                    <tr class="active">
                        <td style="width: 120px; vertical-align: middle">商品描述</td>
                        <td>
                            <textarea rows="5" cols="80" name="p.pdesc" class="form-control">${p.pdesc}</textarea>
                        </td>
                    </tr>
                    <tr class="active">
                        <td style="width: 120px; vertical-align: middle">商品图片</td>
                        <td>
                            <input type="file" name="cover" class="form-control" value="${p.picPath}"/>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><input type="submit" style="width: 200px;" class="btn btn-success" value="修改"></td>
                    </tr>
                </table>
            </form>
        </div>
        <div class="col-md-2"></div>
    </div>
    <div class="row">
        <div class="col-md-4"></div>
        <div class="col-md-4"></div>
        <div class="col-md-4"></div>
    </div>
</div>

</body>
</html>
